<template>
  <Drawer
      v-model="drawer.value"
      title="菜单"
      @ok="handleOk"
      @close="handleClose"
  >
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      label-width="100px"
    >
      <el-form-item label="菜单名称" prop="menu_name">
        <el-input v-model="formData.menu_name"></el-input>
      </el-form-item>
      <el-form-item label="菜单类型" prop="menu_type">
        <el-radio-group v-model="formData.menu_type">
          <el-radio :value="0" border>目录</el-radio>
          <el-radio :value="1" border>菜单</el-radio>
          <el-radio :value="2" border>按钮</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="上级菜单" prop="menu_parent_id" v-if="formData.menu_type === 1">
        <el-tree-select
            check-strictly
            :render-after-expand="false"
            show-checkbox
            v-model="formData.menu_parent_id"
            placeholder="请选择上级目录"
        />
      </el-form-item>
      <el-form-item label="菜单路径" prop="menu_url" v-if="formData.menu_type !== 2">
        <el-input v-model="formData.menu_name"></el-input>
      </el-form-item>
      <el-form-item label="菜单组件" prop="menu_component" v-if="formData.menu_type === 1">
        <el-input v-model="formData.menu_component"></el-input>
      </el-form-item>
      <el-form-item label="菜单图标" prop="menu_icon" >
        <InputIcon v-model="formData.menu_icon"></InputIcon>
      </el-form-item>
    </el-form>
  </Drawer>
</template>

<script lang="ts">
export default {
  name: "MenuModal"
}
</script>

<script setup lang="ts">
import {onMounted, reactive, ref} from "vue"
import Drawer from '@/components/Drawer.vue'
import {SystemMenuAdd} from '@/type/system.menu'
import {FormInstance, FormRules} from 'element-plus'
import InputIcon from '@/components/InputIcon.vue'

const form = ref<FormInstance>()

const drawer = reactive<{
  value: boolean
}>({
  value: false
})

const formData = reactive<SystemMenuAdd>({
  menu_name: "",
  menu_url: "",
  menu_type: null,
  menu_code: 0,
  menu_icon: "",
  sort: 0,
  menu_component: "",
  is_show: 0,
  menu_parent_id: null,
  is_delete: 0
})

const rules:FormRules<SystemMenuAdd> = {
  menu_name: [
    {
      required: true,
      message: "请输入菜单名称",
      trigger: "blur"
    }
  ],
  menu_url: [
    {
      required: true,
      message: "请输入菜单路径",
      trigger: "blur"
    }
  ],
  menu_type: [
    {
      required: true,
      message: "请输入菜单类型",
      trigger: "blur"
    }
  ],
  menu_code: [],
  menu_icon: [
    {
      required: true,
      message: "请选择菜单图标",
      trigger: "blur"
    }
  ],
  sort: [],
  menu_component: [
    {
      required: true,
      message: "请输入菜单组件",
      trigger: "blur"
    }
  ],
  is_show: [],
  menu_parent_id: [
    {
      required: false,
      message: "请选择上级目录",
      trigger: "blur"
    }
  ],
  is_delete: []
}

function init () {
  drawer.value = true
}

const handleOk = () => {

}

const handleClose = () => {

}

defineExpose({
  init
})


onMounted( () => {
} )
</script>

<style scoped lang="scss">

</style>
